package com.aabte.design2.creational.abstractfactory;

import com.aabte.design2.creational.abstractfactory.mac.MacFactory;
import com.aabte.design2.creational.abstractfactory.win.WinFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * 程序会根据当前配置或环境设定选择工厂类型，并在运行时创建工厂（通常在初
 * 始化阶段）。
 *
 * @author Daniel
 * @version 1.0
 * @date 2020/5/2
 */
public class ApplicationConfigurator {

    public static void main(String[] args) {
        GUIFactory factory = null;

        Map<String, String> config = readApplicationConfigFile();
        String os = config.get("os");
        switch (os) {
            case "windows":
                factory = new WinFactory();
                break;
            case "mac":
                factory = new MacFactory();
                break;
        }

        Application app = new Application(factory);
        app.createUI();
        app.paint();
    }

    private static Map<String, String> readApplicationConfigFile() {
        Map<String, String> config = new HashMap<>(1);
        config.put("os", "windows");
        return config;
    }

}
